<template>
  <transition appear name="slide">
    <music-list :title="title" :bg-image="bgImage" :songs = "songs"></music-list>
  </transition>
</template>

<script type="text/ecmascript-6">
  import MusicList from '../../components/music-list/music-list.vue'
  import { getDiscList } from '../../api/recommend'
  import { SUCCESS_OK } from '../../api/config'
  import { mapGetters } from 'vuex'
  import { createSong } from '../../common/js/song'

  export default {
    data () {
      return {
        songs: []
      }
    },
    computed: {
      title () {
        return this.disc.title
      },
      bgImage () {
        return this.disc.cover
      },
      ...mapGetters([
        'disc'
      ])
    },
    created () {
      this._getDiscList()
    },
    methods: {
      _getDiscList () {
        if (!this.disc.content_id) {
          this.$router.push('/recommend')
        }
        getDiscList(this.disc.content_id, (res) => {
          // console.log(res.data.cdlist[0].songlist)
          if (SUCCESS_OK === res.status) {
            this.songs = this._normalLizeSongs(res.data.cdlist[0].songlist)
          //  console.log(this.discList)
          }
        })
      },
      _normalLizeSongs (list) {
        let ret = []
        list.forEach((item) => {
          if (item.id) {
            ret.push(createSong(item))
          }
        })
        return ret
      }
    },
    components: {
      MusicList
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  .slide-enter-active, .slide-leave-active
    transition: all 0.3s

  .slide-enter, .slide-leave-to
    transform: translate3d(100%, 0, 0)
</style>
